Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException throws on Windows when setting Cookies on .NET MAUI WebView #24846

Merged
merged 18 commits into from
Nov 26, 2024

Conversation

NanthiniMahalingam
Copy link
Contributor

@NanthiniMahalingam NanthiniMahalingam commented Sep 20, 2024

Root Cause

While setting a cookie in MAUI WebView, CoreWebView2 is null before the CoreWebView2Initialized event triggered.

Description of Change

Added the null condition for CoreWebView2 property while sync platform cookie method.

Issues Fixed

Fixes #18452

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Output images
Before changes
image

After changes
image

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Sep 20, 2024
@jfversluis
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@NanthiniMahalingam NanthiniMahalingam marked this pull request as ready for review September 23, 2024 05:03
@NanthiniMahalingam NanthiniMahalingam requested a review from a team as a code owner September 23, 2024 05:03
@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho
Copy link
Member

/rebase

@rmarinho
Copy link
Member

rmarinho commented Sep 27, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho rmarinho modified the milestones: .NET 9 Planning, .NET 8 SR9 Sep 27, 2024
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

1 similar comment
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen modified the milestones: .NET 8 SR9, .NET 9 SR1 Oct 1, 2024
@rmarinho
Copy link
Member

rmarinho commented Oct 3, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies

By under I just meant switch the place of the call here

image

So change the code to be

UpdateUserAgent
webViewHandler.SyncPlatformCookies(platformWebView.CoreWebView2.Source).FireAndForget();

vs

webViewHandler.SyncPlatformCookies(platformWebView.CoreWebView2.Source).FireAndForget();
UpdateUserAgent

{
sender.UpdateUserAgent(handler.VirtualView);
handler.SyncPlatformCookies(sender.CoreWebView2.Source).FireAndForget();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the source will be set to the right value at this point

image

For the UItest can you add a part that validates the cookie was set?

like maybe after navigated has fired you can read from the cookies to see if the cookie you added is present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've added cookie validation to the UI test as per your suggestion. Could you please verify once?

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

/azp run

@NanthiniMahalingam
Copy link
Contributor Author

/rebase

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis jfversluis merged commit f115e57 into dotnet:main Nov 26, 2024
104 checks passed
@sheiksyedm sheiksyedm added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 6, 2024
@samhouts samhouts added fixed-in-9.0.21 fixed-in-net8.0-nightly This may be available in a nightly release! labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution fixed-in-9.0.21 fixed-in-net8.0-nightly This may be available in a nightly release! partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows 🪟
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[regression/8.0.0-rc.2.9373] Setting Cookies on .NET MAUI WebView on Windows throws NullReferenceException
8 participants